import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/layout/index.vue'
const router = createRouter({
  history: createWebHashHistory(),
  scrollBehavior: () => {
    return {
      top: 0
    }
  },
  routes: [
    //首页
    {
      path: '/',
      component: Layout,
      children: [
        //首页路由
        { path:'',component: () => import('@/views/home/index.vue')},
        // 一级分类路由
        {
          path: '/category/:id',
          component: () => import('@/views/category/index.vue')
        },
        // 二级分类路由
        {
          path: '/category/sub/:id',
          component: () => import('@/views/category/sub.vue')
        },
        {
          path: '/goods/:id',
          component: () => import('@/views/goods/index.vue'),
        },
      ]
    },
    // 登录
    {
      path: '/login',
      component: () => import('@/views/Login/index.vue')//路由懒加载
    },
    {
      path: '/test',
      component: () => import ('@/views/test/index.vue')
    }
  ]
})
export default router